package com.android.accessibility.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.android.accessibility.R;
import com.android.accessibility.base.BaseActivity;
import com.android.accessibility.utils.Utils;

public class GlobalTipActivity extends BaseActivity implements android.view.View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.forward_result_layout);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        getWindow().setGravity(Gravity.CENTER | Gravity.TOP);
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.y = Utils.dp2px(this, 48);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        p.width = (int)(dm.widthPixels * 0.9f);
        getWindow().setAttributes(p);
        View view = findViewById(R.id.ok);
        view.setOnClickListener(this);
        TextView resultTag = (TextView) findViewById(R.id.result_tag);
        TextView resultTip = (TextView) findViewById(R.id.result_tip);
        boolean success = false;
        Intent intent = getIntent();
        String failureTip = null;
        if (intent != null) {
            success = intent.getBooleanExtra("forward_result", false);
            failureTip = intent.getStringExtra("failure_tip");
        }
        if (success) {
            resultTag.setText(R.string.forward_success);
            resultTip.setText(R.string.forward_success_tip);
            resultTag.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.icon_success, 0, 0);
        } else {
            resultTag.setText(R.string.forward_failure);
            resultTip.setText(failureTip);
            resultTag.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.icon_failure, 0, 0);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ok) {
            finish();
        }
    }
}
